<%--
  Created by IntelliJ IDEA.
  User: kkk
  Date: 2022/8/14
  Time: 9:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>列表</title>
    <script src="js/jquery.js"></script>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <base href="${pageContext.request.contextPath}/">
</head>
<body>
<form action="item/addCard.jsp">
    <h2 style="margin-left: 100px">办公室门禁管理系统</h2>
    <input type="submit" value="办卡">
</form>
    <table border="1">
        <tr>
            <th>持卡人姓名</th>
            <th>持卡人身份证号</th>
            <th>启用状态</th>
            <th>办卡日期</th>
            <th>操作</th>
        </tr>
        <c:forEach items="${list}" var="lists">
            <tr>
                <td>${lists.userName}</td>
                <td>${lists.idNumber}</td>
                <td class="${lists.id}" >${lists.status eq 1 ?'启用' :'禁用'}</td>
                <td>${lists.createDate}</td>
                <td>
                    <a href="JavaScript:check(${lists.id})" class="${lists.id}">${lists.status eq 1 ? '禁用' : '启用' }</a>
                </td>
            </tr>
        </c:forEach>
    </table>
<p  style="margin-left: 100px" id="p" ><%=request.getAttribute("change")%></p>
</body>
<script>
    function check(id) {
        //获取操作状态
        var tet=$("."+id).get(1).innerText;
        if (confirm("确定"+tet+"门禁卡？")){
            $.get("CheckStatus_Servlet","id="+id+"&status="+(tet=="启用"?1:0),function (data) {
                    if (data==="true") {
                        location.href="ListView_Servlet?status="+tet;
                        //互换操作
                        // $("."+id).get(0).innerText=$("."+id).get(0).innerText=="启用"?"禁用":"启用";
                        // $("."+id).get(1).innerText=$("."+id).get(1).innerText=="启用"?"禁用":"启用";
                        // $('#p').text(tet+"成功");
                    }else {
                        $('#p').text(tet+"失败");
                    }
                })
        }
    }
</script>
</html>
